package com.shop2cn.app.liveseller.testcase;

import java.io.IOException;
import java.util.Date;
import java.util.Map;
import java.util.Random;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.shop2cn.app.liveseller.parameter.CreateSellerLiveBean;
import com.shop2cn.app.liveseller.service.CreateSellerLiveCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.LiveRoomShop2cnCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.livesellerShop2cn.*;
import com.ymttest.database.sqlwapper.livesellerShop2cn.LiveRoomShop2cnWapper;
import com.ymttest.utils.DesUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ChineseName;

/**
 * 创建互动直播 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_CreateSellerLive {
	private static CreateSellerLiveBean createsellerliveBean;
	private static CreateSellerLiveCall createsellerliveCall;
	private static LiveRoomShop2cnWapper LiveRoomShop2cnWapper;
	private static int sellerId ;
	private static String token ;
	private static int csId;
	private static String cstoken;

	@BeforeClass
	public static void setUp() throws Exception {
		Logger.createResultFile("创建互动直播");
		sellerId = GodmchManageCallService.CreateSellerMch();
		token=AuthCallServiceV2.createToken(sellerId, "app");
		csId = GodmchManageCallService.bindClientService(
				sellerId, 1);
		cstoken = AuthCallServiceV2.createToken(csId, "app");
	}
	

	@Before
	public void caseUp() {
		createsellerliveBean = new CreateSellerLiveBean();
		createsellerliveCall = new CreateSellerLiveCall();
		LiveRoomShop2cnWapper = new LiveRoomShop2cnWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(createsellerliveCall.getOpurl());
		LiveRoomShop2cnWapper = null;
	}

	@After
	public void caseDown() {

		Logger.end();
	}
	
	private void verifyDBGroupId(LiveRoom livedto, int liveid) throws Exception {
		Logger.comment("数据库验证");
		LiveRoom dblive = LiveRoomShop2cnWapper.selectLiveRoomById(liveid);
		
		int diff1=YMTDateUtil.diffSecond(new Date(Long.valueOf(livedto.getEndTime())),  YMTDateUtil.getDate( dblive.getEndTime(), YMTDateUtil.YMDHMSS));
//		Logger.debug(new Date(Long.valueOf(livedto.getEndTime()))+"："+YMTDateUtil.getDate( dblive.getEndTime(), YMTDateUtil.YMDHMSS)+"："+diff1);
		Logger.verifyEquals(true ,diff1<5, "验证EndTime");
		//创建一个默认
		Logger.verifyNotNull(dblive.getGroupId(), "验证GroupId");
		int diff2=YMTDateUtil.diffSecond(new Date(Long.valueOf(livedto.getStartTime())),  YMTDateUtil.getDate( dblive.getStartTime(), YMTDateUtil.YMDHMSS));
		Logger.verifyEquals(true ,diff2<5, "验证StartTime");
		Logger.verifyEquals(livedto.getLatitude(), dblive.getLatitude(), "验证Latitude");
		Logger.verifyEquals(livedto.getLongitude(), dblive.getLongitude(), "验证Longitude");
		Logger.verifyEquals(livedto.getLiveAddress(), dblive.getLiveAddress(), "验证LiveAddress");
		Logger.verifyEquals(livedto.getLiveCover(), dblive.getLiveCover(), "验证LiveCover");
		Logger.verifyEquals(livedto.getLiveTitle(), dblive.getLiveTitle(), "验证LiveTitle");
		Logger.verifyEquals(livedto.getShoppingAddress(), dblive.getShoppingAddress(), "验证ShoppingAddress");
		Logger.verifyEquals(livedto.getPreVideoHeight(), dblive.getPreVideoHeight(), "验证PreVideoHeight");
		Logger.verifyEquals(livedto.getPreVideoLength(), dblive.getPreVideoLength(), "验证PreVideoLength");
		Logger.verifyEquals(livedto.getPreVideoPic(), dblive.getPreVideoPic(), "验证PreVideoPic");
		Logger.verifyEquals(livedto.getPreVideoWidth(), dblive.getPreVideoWidth(), "验证PreVideoWidth");
		Logger.verifyEquals(livedto.getSellerName(), dblive.getSellerName(), "验证SellerName");
		Logger.verifyEquals(livedto.getUserId(), dblive.getUserId(), "验证UserId");
		Logger.verifyEquals(livedto.getPreVideoUrl(), dblive.getPreVideoUrl(), "验证PreVideoUrl");
		Logger.verifyNotNull(dblive.getPushUrl(), "验证PushUrl");
		String pushurl = DesUtil.decrypt(dblive.getPushUrl(), DesUtil.DES_KEY_STRING, DesUtil.DES_IVPARAMETER);
		Map mpush = FormatUtil.httpStringToMap(pushurl.split("\\?")[1]);
		String sourcepushsecret = LiveRoomShop2cnCallService.LiveAntiKey + LiveRoomShop2cnCallService.BizId + "_" + EnvSetup.getEnv().toUpperCase() + "_" + liveid
				+ mpush.get("txTime").toString();
		String pushtxsecret = TestDataManager.getMD5(sourcepushsecret.getBytes());
		Logger.verifyEquals(mpush.get("txSecret").toString(), pushtxsecret, "验证pushtxsecret");
		// rtmp://11418.livepush.myqcloud.com/live/11418_52?txSecret=80747057322436595a4aaf0b1cb3d71a&txTime=59EAEEE1
		Logger.verifyNotNull(dblive.getPlayUrl(), "验证PlayUrl");
//		Logger.verifyNotNull(dblive.getContinentName(), "验证ContinentName");
//		Logger.debug(FormatUtil.beanToGSONString(JUserCallService.getSellerInfo(livedto.getUserId())));
//		SellerBaseInfo sinfo = JUserCallService.getSellerInfo(livedto.getUserId());
//		Logger.verifyEquals(sinfo.getContinentName(),dblive.getContinentName(), "验证ContinentName");
//		Logger.verifyEquals(sinfo.getLiveCountry(), dblive.getCountryId(), "验证CountryId");
		// String
		// playUrl=DesUtil.decrypt(dblive.getPlayUrl(),DesUtil.DES_KEY_STRING,DesUtil.DES_IVPARAMETER);
		// Map mplay=FormatUtil.httpStringToMap(playUrl.split("\\?")[1]);
		// String
		// playtxsecret=TestDataManager.getMD5(sourcepushsecret.getBytes());
		// Logger.verifyEquals(mplay.get("txSecret").toString(), playtxsecret,
		// "验证pushtxsecret");
		// rtmp://11418.liveplay.myqcloud.com/live/11418_52?txSecret=80747057322436595a4aaf0b1cb3d71a&txTime=59EAEEE1
	}
	
	private void verifyDB(LiveRoom livedto, int liveid) throws Exception {
		Logger.comment("数据库验证");
		LiveRoom dblive = LiveRoomShop2cnWapper.selectLiveRoomById(liveid);
		int diff1=YMTDateUtil.diffSecond(new Date(Long.valueOf(livedto.getEndTime())),  YMTDateUtil.getDate( dblive.getEndTime(), YMTDateUtil.YMDHMSS));
//		Logger.debug(new Date(Long.valueOf(livedto.getEndTime()))+"："+YMTDateUtil.getDate( dblive.getEndTime(), YMTDateUtil.YMDHMSS)+"："+diff1);
		Logger.verifyEquals(true ,diff1<5, "验证EndTime");
		Logger.verifyEquals(livedto.getGroupId(), dblive.getGroupId(), "验证GroupId");
		int diff2=YMTDateUtil.diffSecond(new Date(Long.valueOf(livedto.getStartTime())),  YMTDateUtil.getDate( dblive.getStartTime(), YMTDateUtil.YMDHMSS));
		Logger.verifyEquals(true ,diff2<5, "验证StartTime");
		Logger.verifyEquals(livedto.getLatitude(), dblive.getLatitude(), "验证Latitude");
		Logger.verifyEquals(livedto.getLongitude(), dblive.getLongitude(), "验证Longitude");
		Logger.verifyEquals(livedto.getLiveAddress(), dblive.getLiveAddress(), "验证LiveAddress");
		Logger.verifyEquals(livedto.getLiveCover(), dblive.getLiveCover(), "验证LiveCover");
		Logger.verifyEquals(livedto.getLiveTitle(), dblive.getLiveTitle(), "验证LiveTitle");
		Logger.verifyEquals(livedto.getShoppingAddress(), dblive.getShoppingAddress(), "验证ShoppingAddress");
		Logger.verifyEquals(livedto.getPreVideoHeight(), dblive.getPreVideoHeight(), "验证PreVideoHeight");
		Logger.verifyEquals(livedto.getPreVideoLength(), dblive.getPreVideoLength(), "验证PreVideoLength");
		Logger.verifyEquals(livedto.getPreVideoPic(), dblive.getPreVideoPic(), "验证PreVideoPic");
		Logger.verifyEquals(livedto.getPreVideoWidth(), dblive.getPreVideoWidth(), "验证PreVideoWidth");
		Logger.verifyEquals(livedto.getSellerName(), dblive.getSellerName(), "验证SellerName");
		Logger.verifyEquals(livedto.getUserId(), dblive.getUserId(), "验证UserId");
		Logger.verifyEquals(livedto.getPreVideoUrl(), dblive.getPreVideoUrl(), "验证PreVideoUrl");
		if(livedto.getBuyerShow()!=null) {
			Logger.verifyEquals(livedto.getBuyerShow(), dblive.getBuyerShow(), "验证getBuyerShow");
		}
		//LiveInherit
		if(livedto.getLiveInherit()!=null) {
			Logger.verifyEquals(livedto.getLiveInherit(), dblive.getLiveInherit(), "验证LiveInherit");
		}
		Logger.verifyNotNull(dblive.getPushUrl(), "验证PushUrl");
		String pushurl = DesUtil.decrypt(dblive.getPushUrl(), DesUtil.DES_KEY_STRING, DesUtil.DES_IVPARAMETER);
		Map mpush = FormatUtil.httpStringToMap(pushurl.split("\\?")[1]);
		String sourcepushsecret = LiveRoomShop2cnCallService.LiveAntiKey + LiveRoomShop2cnCallService.BizId + "_" + EnvSetup.getEnv().toUpperCase() + "_" + liveid
				+ mpush.get("txTime").toString();
		String pushtxsecret = TestDataManager.getMD5(sourcepushsecret.getBytes());
		Logger.verifyEquals(mpush.get("txSecret").toString(), pushtxsecret, "验证pushtxsecret");
		// rtmp://11418.livepush.myqcloud.com/live/11418_52?txSecret=80747057322436595a4aaf0b1cb3d71a&txTime=59EAEEE1
		Logger.verifyNotNull(dblive.getPlayUrl(), "验证PlayUrl");
//		Logger.verifyNotNull(dblive.getContinentName(), "验证ContinentName");
//		Logger.debug(FormatUtil.beanToGSONString(JUserCallService.getSellerInfo(livedto.getUserId())));
//		SellerBaseInfo sinfo = JUserCallService.getSellerInfo(livedto.getUserId());
//		Logger.verifyEquals(sinfo.getContinentName(),dblive.getContinentName(), "验证ContinentName");
//		Logger.verifyEquals(sinfo.getLiveCountry(), dblive.getCountryId(), "验证CountryId");
		// String
		// playUrl=DesUtil.decrypt(dblive.getPlayUrl(),DesUtil.DES_KEY_STRING,DesUtil.DES_IVPARAMETER);
		// Map mplay=FormatUtil.httpStringToMap(playUrl.split("\\?")[1]);
		// String
		// playtxsecret=TestDataManager.getMD5(sourcepushsecret.getBytes());
		// Logger.verifyEquals(mplay.get("txSecret").toString(), playtxsecret,
		// "验证pushtxsecret");
		// rtmp://11418.liveplay.myqcloud.com/live/11418_52?txSecret=80747057322436595a4aaf0b1cb3d71a&txTime=59EAEEE1
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_001() {
		Logger.start(true, "创建互动直播成功");
		try {
			sellerId = GodmchManageCallService.CreateSellerMch();
			token=AuthCallServiceV2.createToken(sellerId, "app");
			//ymt-pars: accesstoken=
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			Logger.debug("ymt-pars:"+ head);
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			JsonObject data = createsellerliveCall.getJsonObject();
			Logger.verifyEquals(true, data.get("result").getAsBoolean(), "验证Result");
			createsellerliveBean.getLiveDto().setUserId(sellerId);
			verifyDB(createsellerliveBean.getLiveDto(), data.get("liveId").getAsInt());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_002() {
		Logger.start(true, "不输入ymt-pars失败");
		try {
			LiveRoomShop2cnCallService.AutoCloseLiveRoomByUserId(sellerId);
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyIsContains("ymt-pars", createsellerliveCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_003() {
		Logger.start(true, "不输入LiveTitle失败");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.getLiveDto().setLiveTitle(null);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.addHeader("ymt-pars", "accesstoken="+token);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyEquals("标题不能为空", createsellerliveCall.getString("msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_004() {
		Logger.start(true, "创建互动直播成功,标题包含特殊字符");
		try {
			// sql添加：set names utf8mb4;
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			LiveRoomShop2cnCallService.AutoCloseLiveRoomByUserId(sellerId);
			createsellerliveBean.getLiveDto().setLiveTitle("测试特殊字符;😑😊😳");
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			JsonObject data = createsellerliveCall.getJsonObject();
			Logger.verifyEquals(true, data.get("result").getAsBoolean(), "验证Result");
			createsellerliveBean.getLiveDto().setUserId(sellerId);
			verifyDB(createsellerliveBean.getLiveDto(), data.get("liveId").getAsInt());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_005() {
		Logger.start(true, "开始时间早于当前时间失败");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.getLiveDto().setStartTime(YMTDateUtil.getTimeBySecond(-100*60).toString());
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("code"), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_006() {
		Logger.start(true, "结束时间早于开始时间失败");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.getLiveDto().setEndTime(YMTDateUtil.getTimeBySecond(-100*60).toString());
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyEquals("直播结束时间必须大于开始时间", createsellerliveCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_007() {
		Logger.start(true, "开始时间晚于30天失败");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.getLiveDto().setStartTime(YMTDateUtil.getTimeBySecond(31*24*60*60).toString());
			createsellerliveBean.getLiveDto().setEndTime(YMTDateUtil.getTimeBySecond(32*24*60*60).toString());
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyIsContains("直播开始时间最多只能设置为", createsellerliveCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_008() {
		Logger.start(true, "标题长度小于18互动直播创建失败");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.getLiveDto().setLiveTitle("Test");
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyIsContains("直播名称长度需在", createsellerliveCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_009() {
		Logger.start(true, "标题长度小大于36互动直播创建失败");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.getLiveDto().setLiveTitle("测试标题长度大于三十六的情况试试这样能否创建");
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyIsContains("直播名称长度需在", createsellerliveCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_010() {
		//最大直播时间限制？24
		Logger.start(true, "直播时间大于24小时失败");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.getLiveDto().setStartTime(YMTDateUtil.getTimeBySecond(10*60).toString());
			createsellerliveBean.getLiveDto().setEndTime(YMTDateUtil.getTimeBySecond(2*24*60*60).toString());
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyIsContains("直播时间不能大于", createsellerliveCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_011() {
		Logger.start(true, "重复创建互动直播失败");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			createsellerliveCall.callService();
			Logger.verifyEquals("201", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyIsContains("不可重复创建", createsellerliveCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_012() {
		Logger.start(true, "创建2个未来的互动直播成功");
		try {
			//可以创建2个未来直播 20180508
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			LiveRoomShop2cnCallService.AutoCloseLiveRoomByUserId(sellerId);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			createsellerliveBean.getLiveDto().setGroupId(TestDataManager.getRandomNum(13));
			createsellerliveBean.getLiveDto().setStartTime(YMTDateUtil.getTimeBySecond(220*60).toString());
			createsellerliveBean.getLiveDto().setEndTime(YMTDateUtil.getTimeBySecond(300*60).toString());
			createsellerliveCall.callService();
			Logger.verifyEquals("true", createsellerliveCall.getString("result"), "验证result");
//			Logger.verifyEquals("即将开始直播只能创建一场，不可重复创建", createsellerliveCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_013() {
		Logger.start(true, "正在直播推流的直播时创建一个未来的互动直播成功");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(createsellerliveBean,sellerId);
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			createsellerliveBean.getLiveDto().setGroupId(String.valueOf(YMTDateUtil.getDate().getTime()));
			createsellerliveBean.getLiveDto().setStartTime(YMTDateUtil.getTimeBySecond(220*60).toString());
			createsellerliveBean.getLiveDto().setEndTime(YMTDateUtil.getTimeBySecond(300*60).toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			JsonObject data = createsellerliveCall.getJsonObject();
			Logger.verifyEquals("true", createsellerliveCall.getString("result"), "验证result");
			createsellerliveBean.getLiveDto().setUserId(sellerId);
			verifyDB(createsellerliveBean.getLiveDto(), data.get("liveId").getAsInt());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_014() {
		Logger.start(true, "不输入PreVideoPic失败");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.getLiveDto().setPreVideoPic(null);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyEquals("预告短片封面不能为空", createsellerliveCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_015() {
		Logger.start(true, "不输入PreVideoUrl失败");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.getLiveDto().setPreVideoUrl(null);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyEquals("预告短片不能为空", createsellerliveCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	@Ignore
	public void Tc_CreateSellerLive_016() {
		Logger.start(true, "不输入LiveAddress失败");
		try {
			
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.getLiveDto().setLiveAddress("");
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyEquals("直播地不能为空", createsellerliveCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_017() {
		Logger.start(true, "不输入StartTime失败");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.getLiveDto().setStartTime(null);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyEquals("开始时间不能为空", createsellerliveCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_018() {
		Logger.start(true, "不输入EndTime失败");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.getLiveDto().setEndTime(null);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyEquals("结束时间不能为空", createsellerliveCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

//	@Test
//	@Category({ P1.class })
//	@TestCase
//	public void Tc_CreateSellerLive_019() {
//		Logger.start(true, "groupid为空失败");
//		try {
//			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
//			LiveRoomShop2cnCallService.AutoCloseLiveRoomByUserId(csellerId);
//			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
//			createsellerliveBean.getLiveDto().setGroupId(null);
//			createsellerliveCall.setData(createsellerliveBean);
//			createsellerliveCall.callService();
//			Logger.verifyEquals("400", createsellerliveCall.getString("code"), "验证Code");
//			Logger.verifyIsContains("不能为空", createsellerliveCall.getString("msg"), "验证Msg");
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_020() {
		Logger.start(true, "直播1已经开始,第二个互动直播开始时间在这个结束时间之前失败");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(createsellerliveBean,sellerId);
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			createsellerliveBean.getLiveDto().setStartTime(YMTDateUtil.getTimeBySecond(80*60).toString());
			createsellerliveBean.getLiveDto().setEndTime(YMTDateUtil.getTimeBySecond(300*60).toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			Logger.verifyEquals("201", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyEquals("此时间段已存在直播，不可重复创建", createsellerliveCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_021() {
		Logger.start(true, "直播1未开始但是到了开始时间,第二个互动直播开始时间在这个结束时间之前");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			LiveRoomShop2cnCallService.AutoCloseLiveRoomByUserId(sellerId);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(createsellerliveBean,sellerId);
			// LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(),
			// createlive.getUserId());
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(createlive.getId());
			createsellerliveBean.getLiveDto().setGroupId(String.valueOf(YMTDateUtil.getDate().getTime()));
			createsellerliveBean.getLiveDto().setStartTime(YMTDateUtil.getTimeBySecond(2000*60).toString());
			createsellerliveBean.getLiveDto().setEndTime(YMTDateUtil.getTimeBySecond(2100*60).toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			Logger.verifyEquals("true", createsellerliveCall.getString("result"), "验证result");
			Logger.verifyNotNull(createsellerliveCall.getString("liveId"), "验证liveId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_022() {
		Logger.start(true, "groupid重复，失败");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			LiveRoomShop2cnCallService.AutoCloseLiveRoomByUserId(sellerId);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			LiveRoomShop2cnCallService.AutoCloseLiveRoomByUserId(sellerId);
			createsellerliveCall.callService();
			Logger.verifyEquals("500", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyIsContains("系统异常", createsellerliveCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_023() {
		Logger.start(true, "客服创建互动直播失败");
		try {
			//ymt-pars: accesstoken=
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+cstoken;
			Logger.debug("ymt-pars:"+ head);
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("code"), "验证Code");
			Logger.verifyEquals("客服不能创建直播", createsellerliveCall.getString("msg"), "验证msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	//group有限 不传会自动创建 所以注释
	public void Tc_CreateSellerLive_034() {
		Logger.start(true, "服务端创建互动直播 GroupId 为空");
		try {
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			LiveRoomShop2cnCallService.AutoCloseLiveRoomByUserId(sellerId);
			createsellerliveBean.getLiveDto().setGroupId(null);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			JsonObject data = createsellerliveCall.getJsonObject();
			Logger.verifyEquals(true, data.get("result").getAsBoolean(), "验证Result");
			createsellerliveBean.getLiveDto().setUserId(sellerId);
			verifyDBGroupId(createsellerliveBean.getLiveDto(), data.get("liveId").getAsInt());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_035() {
		Logger.start(true, "创建互动直播成功-title4个汉字");
		try {
			//ymt-pars: accesstoken=
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			String title= "";
			Random random = new Random();
			for(int size=0;size<4;size++) {
				int i = random.nextInt(ChineseName.Ming.size());
				String temp_m = ChineseName.Ming.get(i);
				int j = random.nextInt(temp_m.length());
				title += temp_m.substring(j, j + 1);
			}
			createsellerliveBean.getLiveDto().setLiveTitle(title);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			Logger.debug("ymt-pars:"+ head);
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			JsonObject data = createsellerliveCall.getJsonObject();
			Logger.verifyEquals(true, data.get("result").getAsBoolean(), "验证Result");
			createsellerliveBean.getLiveDto().setUserId(sellerId);
			verifyDB(createsellerliveBean.getLiveDto(), data.get("liveId").getAsInt());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_036() {
		Logger.start(true, "创建互动直播成功-新增字段buyerShow");
		try {
			//ymt-pars: accesstoken=
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.getLiveDto().setBuyerShow(true);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			Logger.debug("ymt-pars:"+ head);
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			JsonObject data = createsellerliveCall.getJsonObject();
			Logger.verifyEquals(true, data.get("result").getAsBoolean(), "验证Result");
			createsellerliveBean.getLiveDto().setUserId(sellerId);
			verifyDB(createsellerliveBean.getLiveDto(), data.get("liveId").getAsInt());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_037() {
		Logger.start(true, "创建互动直播成功新增参数LiveInherit");
		try {
			sellerId = GodmchManageCallService.CreateSellerMch();
			token=AuthCallServiceV2.createToken(sellerId, "app");
			//ymt-pars: accesstoken=
			createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			createsellerliveBean.getLiveDto().setLiveInherit(true);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			String head="accesstoken="+token;
			Logger.debug("ymt-pars:"+ head);
			createsellerliveCall.addHeader("ymt-pars", head);
			createsellerliveCall.callService();
			JsonObject data = createsellerliveCall.getJsonObject();
			Logger.verifyEquals(true, data.get("result").getAsBoolean(), "验证Result");
			createsellerliveBean.getLiveDto().setUserId(sellerId);
			verifyDB(createsellerliveBean.getLiveDto(), data.get("liveId").getAsInt());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}